const express = require('express')
const path = require('path')
const router = require('./router')
//这个中间件用来处理post请求
const bodyParser = require('body-parser')
//处理session的中间件
var session = require('express-session')

const app = express()

app.use('/public/', express.static(path.join(__dirname, '/public')))
app.use('/node_modules/', express.static(path.join(__dirname, '/node_modules')))

// 配置body-parser中间件
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())

//配置express-session
app.use(session({
  secret: 'lzj',    //给数据加个字符串，增加安全性
  resave: false,
  saveUninitialized: true
}))

app.use(router)

app.listen(5000, () => console.log(`App listening on port 5000!`))